// pages/mineModule/consultationManager/consultationManager.js
import request from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isDoctor:true,
    slideButtons:[
      {
        text: '接受',
        type:'primary'
      },{
        type: 'warn',
        text: '拒绝',
      }
    ],
    userButtons:[
      {
        text: '去咨询',
        type:'warn'
      }
    ],
    interactionList: [{
      id: '',
      doctorName: '',
      doctorOpenid: '',
      userOpenid: ''
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let i = 0;
    request.get('/loadInteractionByOpenid', {}).then(res => {
      console.log(res);
      
      res.data.forEach((item) => {
        this.setData({
          ['interactionList['+i+']'] : {
            id: item.interaction.id,
            doctorOpenid: item.interaction.doctorOpenid,
            userOpenid: item.interaction.userOpenid,
            doctorName: item.doctor.name
          }
        })
        i++;
      })
    })
  },
  slideButtonTap(e) { 
    console.log('slide button tap', e.detail)
  },
  userButtonTap(e) {
    console.log('user button tap', e)
    wx.navigateTo({
      url: '/pages/consultation/consultation?thisUserOpenid=' + e.currentTarget.dataset.data.userOpenid+'&otherUserOpenid=' + e.currentTarget.dataset.data.doctorOpenid+'&doctorName='+e.currentTarget.dataset.data.doctorName,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})